package com.example.composemodifiterdemo

import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

/**
 *@author: njb
 *@date:  2023/2/7 11:53
 *@desc:
 */
class ButtonSampleActivity:ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
         setContent {
             ButtonSample()
         }
    }

    @Preview
    @Composable
    fun ButtonSample(){
        Column {
            Button(onClick = { /*TODO*/ }) {
                Text(text = "确认")
            }
            Spacer(modifier = Modifier.width(20.dp))
            Button(onClick = { /*TODO*/ }) {
                Icon(
                    imageVector = Icons.Filled.Done,
                    contentDescription = stringResource(R.string.sure),
                    modifier = Modifier.size(ButtonDefaults.IconSize)
                )
                Spacer(modifier = Modifier.size(ButtonDefaults.IconSpacing))
                Text(text = "确认")
            }
            Spacer(modifier = Modifier.width(20.dp))
            val interactionSource = remember {
                MutableInteractionSource()
            }
            val pressState = interactionSource.collectIsPressedAsState()
            val borderColor = if(pressState.value) Color.Green else Color.White
            Button(onClick = {{

            }},
                border = BorderStroke(2.dp, color = borderColor)
            ) {
                Spacer(modifier = Modifier.size(ButtonDefaults.IconSpacing))
                Text(text = "Long Press")
            }
            Spacer(modifier = Modifier.width(20.dp))
            ExtendedFloatingActionButton(
                icon = { Icon(Icons.Filled.Favorite , contentDescription = null)}, text = {Text("添加到我的收藏")}, onClick = { /*TODO*/ })
        }
    }

    @Composable
    fun InteractionSourceDemo(){
        Column() {
            val interactionSource = remember {
                MutableInteractionSource()
            }
            val pressState = interactionSource.collectIsPressedAsState()
            val borderColor = if(pressState.value) Color.Green else Color.White
            Button(onClick = { /*TODO*/ },
                border = BorderStroke(2.dp, color = borderColor)
            ) {
                Spacer(modifier = Modifier.size(ButtonDefaults.IconSpacing))
                Text(text = "Long Press")
            }
        }
    }

    @Composable
    fun floatButton(){
        ExtendedFloatingActionButton(
            icon = { Icon(Icons.Filled.Favorite , contentDescription = null)}, text = {Text("添加到我的收藏")}, onClick = { /*TODO*/ })
    }
}